<!-- 带箭头的弹出层 -->
<template>
	<view class="comp-bubble-popover">
		<view class="comp-bubble-popover-title" :style="{color: textColor}" :id="domId" @tap="handleShow()">
			{{label}}			
		    <basic-icons :name="icon" size="20rpx" />
		</view>
		<uni-transition :mode-class="['fade']" :styles="maskClass" :duration="duration" :show="show">
		    <view class="comp-bubble-popover-content">
				<view class="triangle" :style="{left: triangleLeft + 'px'}"></view>
				<view class="comp-bubble-popover-content--wrap">
					<view class="contain">
						<slot name="content"></slot>
					</view>
					<view class="footer" v-if="showButton">
						<view class="btn default" @tap="handleCancel">
							{{closeBtn}}						
						</view>
						<view class="btn submit" @tap="handleSubmit">
							{{submitBtn}}						
						</view>
					</view>					
				</view>
			</view>	
			<view class="comp-bubble-popover-mask" @tap="handleClose"></view>
		</uni-transition>		
	</view>
</template>
<script>
import sdk from 'sdk'
export default {
	props: {
		label: { type: String, default:'标题' },
		icon: { type: String, default:'icon-caret' },
		showButton: { type: Boolean, default: true },
		closeBtn: { type: String, default:'重置' },
		submitBtn: { type: String, default:'确定' },
		showCustomPopup: { type: Boolean, default: false },
		duration: { type: Number, default: 300 },
		textColor: { type: String, default:'#1B2431' }
	},
	data() {
		return {
			show:false,
			showAction: false,
			hideAction: false,
			triangleLeft: 11,
			domId: 'comp-bubble-popover-title',
			animationData: {},
			maskClass: {
				'position': 'relative',
				'bottom': 0,
				'top': 0,
				'left': 0,
				'right': 0,
				'zIndex': 2000,
				'backgroundColor': 'rgba(0, 0, 0, 0.4)'
			},
		}
	},
	created() {
		this.domId = 'comp-bubble-popover-title-' + Math.random().toString().replace('0.', '')
	},
	mounted() {
		const that = this
		sdk.createSelectorQuery().in(this).select('#' + this.domId).boundingClientRect(function(e){
				that.triangleLeft = e.left + e.width / 2
		}).exec()
	},
	methods: {
		handleShow() {
			if(this.showCustomPopup) {
				this.$emit('handleClick')
				return
			}		
			this.show = true;
		},
		handleClose() {
			this.show = false;
		},
		handleCancel() {
			this.$emit('cancel')
			this.show = false;
		},
		handleSubmit() {
			this.$emit('submit')
			this.show = false;			
		}
	}
}
</script>
<style lang="less">
.comp-bubble-popover{
	position: relative;
	.comp-bubble-popover-title{
		font-size: 24rpx;
		color: @font_color;
		position: relative;
		display: inline-block;
		padding-right:30rpx;
	}
	.comp-bubble-popover-content{
		min-height:100rpx;
		position: fixed;
		left:0;
		right:0;
		z-index: 1000;
		margin-top:20rpx;
		box-sizing: border-box;
		.comp-bubble-popover-content--wrap{
			position: absolute;
			z-index: 1000;
			left:0;
		    right:0;
			border-radius: 16rpx;
			background: #fff;
			// padding: 20rpx;	
			margin: 0 20rpx 0 20rpx;	
			box-sizing: border-box;
			min-height:100rpx;
			color:@font_color;
			.contain{
				padding: 20rpx 50rpx;
			}
			.footer{
				border-top: 1px solid #FAFAFA;
				margin-top: 10rpx;
				padding: 30rpx 0rpx;
				display: flex;
				justify-content: space-around;
				.btn{
					width:304rpx;
					height:64rpx;
					border-radius: 39rpx;
					border: 1px solid #E7E7E7;
					color: @font_color;
					font-size: 28rpx;
					display: flex;
					justify-content: center;
					align-items: center;
					&.default{
						color:@font_color;
						background: #fff;
					}
					&.submit{
						color: #fff;
						background: @theme_color;
						border: 0;
					}
				}
			}
		}
		.triangle{
			width: 28rpx;
			height: 12rpx;
			position: absolute;
		    z-index: 1000;
			top:-10rpx;
			background: url('/static/triangle.png') no-repeat;
			background-size: 28rpx 12rpx;
			transform: translateX(-50%);
		}
	}
	.comp-bubble-popover-mask{
		position: fixed;
		z-index: 999;
		left:0;
		top:0;
		right:0;
		bottom: 0;
		display: block;
		background: rgba( 0 , 0 , 0 , 0.5);
	}
}
</style>

